#include <iostream>

using namespace std;

const int N = 2e5 + 10;

int q[N];
int n, res;
int dp[N];

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i ++ ) cin >> q[i];
	
	dp[0] = q[0];
	
	res = q[0];
	
	for (int i = 1; i < n; i ++ )
	{
		if (dp[i - 1] < 0) dp[i] = q[i];
		else dp[i] = q[i] + dp[i - 1];
		
		res = max(res, dp[i]);
	}	
	
	
	cout << res << endl;
	
	return 0;
}
